//
//  HCRegisteredViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/22.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCRegisteredViewController.h"

#import "HCRegisteredView.h"

#import "HCRegisterSecondViewController.h"

@interface HCRegisteredViewController () <HCRegisterDelegate> {
    NSString *smsCode;
}

@property (nonatomic, copy) NSString *phoneNO;

@end

@implementation HCRegisteredViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"注册";
    
    HCRegisteredView *rv = [[HCRegisteredView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    rv.delegate = self;
    [self.centerView addSubview:rv];
    
    self.dataRequest.delegate = self;
    
    
    // Do any additional setup after loading the view.
}

-(void)hc_registerCheckPhone:(NSString *)phone {
    [self.dataRequest postHC_RegisterCheck:phone checkString:@"1"];
    _phoneNO = [NSString stringWithFormat:@"%@",phone];
    
    HCUSERDEFUALTS(_phoneNO, @"userphone");
    
}

-(void)hc_registerSurePhone:(NSString *)phone {
    if ([phone isEqualToString:smsCode]) {
        [self.navigationController pushViewController:[[HCRegisterSecondViewController alloc] init] animated:YES];
    }else{
        [XHToast showBottomWithText:@"验证码不正确"];
    }
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"手机号码验证:%@",dictionary);
    
    if ([dictionary[@"stat"] integerValue] == 200) {
        smsCode = [NSString stringWithFormat:@"%@",dictionary[@"param"]];
    }else{
        [XHToast showBottomWithText:@"此手机号码已经注册"];
    }
    
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"失败，验证手机号码");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
